const express = require('express');
const banner = require('../module/banner/banner')
const weather = require('../module/weather/weather')
const index = require('../module/index/index')
const baiduAI = require('../module/baiduAI/index')
const speechSynthesis = require('../module/speechSynthesis/index')
const line = require("../module/line/line");
const router = express.Router();
const fs = require('fs').promises;

router.get('/bannerList', async (req, res, next) => {
  const data = await banner.getBannerList(req)
  res.json(data)
});

router.get('/weather', async ( req, res ) => {
  const data = await weather.getWeather(req)
  res.json(data)
})

router.get('/indexDataCount', async ( req, res ) => {
  const loginStatus = await global.tokenFun.checkToken(req)
  if (loginStatus.loginStatus) {
    const data = await index.indexDataCount({
      ...loginStatus.loginRows,
      ...req.query
    })
    res.json(data)
  }else {
    res.json(loginStatus.msg)
  }
})

router.post('/speechSynthesis', async (req, res) => {
  const data = await speechSynthesis.speechSynthesis(req)
  res.json(data)
})

router.get('/getWorkByTaskId', async (req, res) => {
  const data = await speechSynthesis.getWorkByTaskId({
    taskId: req.query.taskId
  })
  res.json(data)
})

router.post('/generateArticle', async(req, res ) => {
  let data = {}
  if (req.body.text) {
    const nData = {
      text: req.body.text,
      userId: 1
    }
    data = await baiduAI.generateArticle(nData)
  }else {
    data = {
      code: 400,
      msg: '请输入文本',
      data: null
    }
  }
  res.json(data)
})


module.exports = router;
